package com.liao.myapplication;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyOpenHelper extends SQLiteOpenHelper {

    public MyOpenHelper(@Nullable Context context) {
        super(context, "test", null, 2);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table book(id integer primary key autoincrement,bookname varchar(15),author varchar(10))";
        db.execSQL(sql);
        ContentValues values = new ContentValues();
        values.put("bookname", "三国演义");
        values.put("author", "罗贯中");
        db.insert("book", null, values);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("create table user(id integer primary key,username varchar(10),age integer,phone varchar(11))");
    }
}
